package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("增加操作");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名");
        String name1 = scanner.nextLine();
        System.out.println("请输入作者");
        String author1 = scanner.nextLine();
        System.out.println("请输入价格");
        int price1 = scanner.nextInt();
        scanner.nextLine();//上面为int，下面为String,会读入回车键
        System.out.println("请输入类型");
        String type1 = scanner.nextLine();

        Book book = new Book(name1,author1,price1,type1);

        int usedCount = bookList.getUsedSize();

        for (int i = 0; i < usedCount; i++) {
            if(name1.equals(bookList.getBook(i).getName())){
                System.out.println("已存在这本书");
                return;
            }
        }
        bookList.setBook(book,usedCount);

        bookList.setUsedSize(usedCount+1);

    }
}
